 function [Gone,Cone,RRone,euone,SDXone,zmat,NY,NX,NETA,gev,ncof]=modnkxinognolaim(estpr,calpr,indp,con,ind_sv)
% ========================================================================
% XI NOG NOL 
% Baseline with CP, Habit, Indexation but NO Learning 
% Also no output gap 
% Use for SV 
% =========================================================================
% NY=23;
% ystar=17;
% ygap=18; 
% lambdastar=19;
% wstar=20;
% Rstar=21;
% eystar=22;
% elambdastar=23;
NY=16; 
p=1;            % inflation
y=2;            % output
lambda=3;       % multiplier
w=4;            % real wages
R=5;            % interst rate
z=6;            % productivity shock
lambdap=7;      % mark-up shock
pit=8;          % inflation target shock
b=9;            % preference shock
mp=10;          % MP shock!!!
ep=11;          % expectational variables
ey=12;
elambda=13;
p_1=14;
p_2=15;
yobs=16; 

% INDEX for Shocks  
% -------------------------------------------------------------------------
NX=5; 
Rs=1;           % MP
zs=2;           % Technology 
lambdaps=3;     % mark-up
pits=4;         % inflation target
bs=5;           % intertemporal preference

% NETA=5; 
% ystarex=4;
% lambdastarex=5;

NETA=3; 
pex=1; 
yex=2;
lambdaex=3;
% Index for the parameters 
% -------------------------------------------------------------------------
ncof=15;    
numpar=ncof+NX;                    
if nargin < 5 || isempty( ind_sv ) 
    flag_sv = 0 ;
else  
    flag_sv = 1 ;
end 
if nargin == 1 || isempty( calpr ) 
    param=estpr  ; 
else
    param=zeros(numpar,1); 
    param(indp)=estpr; 
    param(con)=calpr; 
end; 
% Non SD parameters 
% -------------------------------------------------------------------------
gamma100=param(1);
pss100=param(2);
rss100=param(3);
niu=param(4);
h=param(5);
xip=param(6);
iotap=param(7);
lambdapss=param(8); 
fp=param(9);
fy=param(10);
rhoR=param(11); 
rhoz=param(12);rholambdap=param(13);rhopit=param(14);rhob=param(15);
% System Matrices 
GAM0=zeros(NY,NY);
GAM1=zeros(NY,NY);
PSI=zeros(NY,NX);
PPI=zeros(NY,NETA);
% SS
rss=rss100/100;
gamma=gamma100/100;
beta=exp(gamma)/(1+rss);
% eq 1, Phillips Curve (p)
% -------------------------------------------------------------------------
GAM0(p,p)=1;
GAM0(p,ep)=-beta/(1+iotap*beta);
GAM1(p,p)=iotap/(1+iotap*beta);
GAM0(p,lambdap)=-1;      
if (1-beta*xip) < eps
    disp('Negative Slope!');
    euone=[];SDXone=[];gev=[];Gone=[];RRone=[];Cone=[];zmat=[];
    return;
end
GAM0(p,w)= -(1-beta*xip)*(1-xip)/((1+iotap*beta)*xip*(1+niu*(1+1/lambdapss))); 





% eq 2, marginal utility of consumption  MAY 5 2007
% -------------------------------------------------------------------------
expg=exp(gamma);
GAM0(y,lambda)=(expg-h*beta)*(expg-h);
GAM0(y,b)=[-(expg-h*beta*rhob)*(expg-h)]*[expg^2+beta*h^2+expg*h]/[(1-rhob)*(expg-h*beta*rhob)*(expg-h)];
GAM0(y,z)=-(beta*h*expg*rhoz-h*expg);
GAM0(y,y)=(expg^2+beta*h^2);
GAM0(y,ey)=-beta*h*expg;
GAM1(y,y)=expg*h;
% eq 3, euler equation
% -------------------------------------------------------------------------
GAM0(lambda,lambda)=1;
GAM0(lambda,R)=-1;
GAM0(lambda,elambda)=-1;
GAM0(lambda,ep)=1;
GAM0(lambda,z)=rhoz;
% eq 4, labor supply equation MAY 5 2007 
% -------------------------------------------------------------------------
GAM0(w,w)=1;
GAM0(w,b)=-1*[expg^2+beta*h^2+expg*h]/[(1-rhob)*(expg-h*beta*rhob)*(expg-h)];       
GAM0(w,y)=-niu;
GAM0(w,lambda)=1;
% eq 5, MP rule 1st sample 
% -------------------------------------------------------------------------
GAM0(R,R)=1;
GAM1(R,R)=rhoR;
GAM0(R,p)=-(1-rhoR)*fp/4;
GAM0(R,p_1)=-(1-rhoR)*fp/4;
GAM0(R,p_2)=-(1-rhoR)*fp/4;
GAM1(R,p_2)=(1-rhoR)*fp/4;
GAM0(R,pit)=(1-rhoR)*(fp-1);
GAM0(R,mp)=-1;
GAM0(R,yobs)= -(1-rhoR)*fy;
% eq 6 - 9, exogenous shocks
% -------------------------------------------------------------------------
GAM0(z,z)=1; GAM1(z,z)=rhoz; PSI(z,zs)=1;
GAM0(lambdap,lambdap)=1; GAM1(lambdap,lambdap)=rholambdap; PSI(lambdap,lambdaps)=1;
GAM0(pit,pit)=1; GAM1(pit,pit)=rhopit; PSI(pit,pits)=1;
GAM0(b,b)=1; GAM1(b,b)=rhob; PSI(b,bs)=1;
GAM0(mp,mp)=1; GAM1(mp,mp)=0; PSI(mp,Rs)=1;
% eq 10 - 14, expectational terms
% -------------------------------------------------------------------------
GAM0(ep,p)=1; GAM1(ep,ep)=1; PPI(ep,pex)=1;
GAM0(ey,y)=1; GAM1(ey,ey)=1; PPI(ey,yex)=1;
GAM0(elambda,lambda)=1; GAM1(elambda,elambda)=1; PPI(elambda,lambdaex)=1;

% % eq 1b
% % -------------------------------------------------------------------------
% GAM0(Rstar,wstar)=1;
% % eq 2b
% % -------------------------------------------------------------------------
% GAM0(ystar,lambdastar)=(expg-h*beta)*(expg-h);
% GAM0(ystar,b)=[-(expg-h*beta*rhob)*(expg-h)]*[expg^2+beta*h^2+expg*h]/[(1-rhob)*(expg-h*beta*rhob)*(expg-h)];
% GAM0(ystar,z)=-(beta*h*expg*rhoz-h*expg);
% GAM0(ystar,ystar)=(expg^2+beta*h^2);
% GAM0(ystar,eystar)=-beta*h*expg;
% GAM1(ystar,ystar)=expg*h;
% % eq 3
% % -------------------------------------------------------------------------
% GAM0(lambdastar,lambdastar)=1;
% GAM0(lambdastar,Rstar)=-1;
% GAM0(lambdastar,elambdastar)=-1;
% GAM0(lambdastar,z)=rhoz;
% % eq 4b, labor supply equation
% % -------------------------------------------------------------------------
% GAM0(wstar,wstar)=1;
% GAM0(wstar,b)=-1*[expg^2+beta*h^2+expg*h]/[(1-rhob)*(expg-h*beta*rhob)*(expg-h)];       
% GAM0(wstar,ystar)=-niu;
% GAM0(wstar,lambdastar)=1;
% % GAM0(eystar,ystar)=1; GAM1(eystar,eystar)=1; PPI(eystar,ystarex)=1;
% % GAM0(elambdastar,lambdastar)=1; GAM1(elambdastar,elambdastar)=1; PPI(elambdastar,lambdastarex)=1;
% % % GAP is ygap=y(t) - y*(t) 
% % GAM0(ygap,ygap)= -1;GAM0(ygap,y)=1;GAM0(ygap,ystar)= -1; 
% eq 15, lagged variables for the state-space repres.

% -------------------------------------------------------------------------
GAM0(p_1,p_1)=1; GAM1(p_1,p)=1;
GAM0(p_2,p_2)=1; GAM1(p_2,p_1)=1;
% -yobs(t) + y(t) + z(t) = y(t-1) 
% yobs(t) = y(t) + z(t) - y(t-1) 
GAM0(yobs,yobs)=-1; GAM0(yobs,y)=1; GAM0(yobs,z)=1; GAM1(yobs,y)=1; 
% ======================================================================
%                   Solution for both samples 
% =======================================================================
% =====================================================================
%                            First Sample 
% ======================================================================
C=zeros(NY,1);

[Gone,C,RRone,fmat,fwt,ywt,gev,euone]=gensys(GAM0,GAM1,C,PSI,PPI) ;
[Gaim,Caim,RRaim,faim,fwaim,ywt,gevaim,euoneaim]=amagensys(GAM0,GAM1,C,PSI,PPI);
if isequal(euone,[1;1])
    % Compare solutions
    comparemat(Gone,Gaim);
    comparemat(C,Caim);
    comparemat(RRone,RRaim);
else
    error('No solution')
end

if ~isequal(euone,[1;1]);
    SDXone=[];gev=[];zmat=[];Cone=[];
    return;
end
% Standard Deviation == for both samples 
if flag_sv == 0 
    SDXone=diag(param(ncof+1:ncof+NX)); 
else 
    SDXone=[]; 
end 
% ================================================
% Z and Cone, Ctwo (indentical)
% ================================================
zmat=zeros(3,NY); 
zmat(1,yobs)=1;
zmat(2,p)=4;
zmat(3,R)=4; 
% Var1 
Cone=zeros(NY,1);
Cone(yobs)=gamma100;
Cone(p)=pss100;
Cone(R)=(pss100+rss100);
ncof=ncof+1; 